package Game_checkPosition;


import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Method;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import FamilyTherapy.Board;
import FamilyTherapy.GCWindow;
import FamilyTherapy.Game;
import FamilyTherapy.MagicToolCard;
import FamilyTherapy.Player;

public class testGame_checkPosition {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void testCheckPosition_3() throws Exception {
		int currentPlayerPos = 7;
		int currentPlayerNo = 0;
		int expectedResult = 3;
				

		Player[] p = { new Player("a", 1), new Player("b", 2) };
		GCWindow gcWindow = new GCWindow();
		p[0].setPosition(currentPlayerPos);
		Game game = new Game();
		Board board = new Board();
		 
		
		int currentEvent= board.getBox(currentPlayerPos);

		Method checkPositionMethod = game.getClass().getDeclaredMethod(
				"checkPosition", GCWindow.class, int.class, Player[].class);
		
		
		checkPositionMethod.setAccessible(true);
				
		//for input
		String data = "y y"; 	//data to be input 
		InputStream stdin = System.in; 
		try {   
			System.setIn(new ByteArrayInputStream(data.getBytes()));
			checkPositionMethod.invoke(game, gcWindow,currentPlayerNo, p);	
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		
		//currentPlayerPos = p[0].getPosition();
		currentEvent = board.getBox(currentPlayerPos);
		
		checkPositionMethod.setAccessible(false);
		System.out.println(currentEvent);
		//System.out.println(p[0].getPosition());
		
		assertEquals(expectedResult, currentEvent);
	}
}
